package com.boot.dog.rest.core;

import com.boot.dog.common.annotation.SysLog;
import com.boot.dog.common.util.ApiResult;
import com.boot.dog.entities.pojo.Area;
import com.boot.dog.entities.vo.Area4ChildVo;
import com.boot.dog.service.AreaService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MaxLv
 * @Date: 2020/1/16
 */
@RestController
@RequestMapping("/core/area")
@AllArgsConstructor
public class AreaRest {

    private final AreaService areaService;


    @PostMapping("/saveArea")
    @SysLog(desc = "添加区域")
    @ApiOperation(value = "添加区域")
    public ApiResult<Void> saveArea(@RequestBody Area area) {
        return areaService.saveArea(area);
    }

    @PostMapping("/editArea")
    @SysLog(desc = "编辑区域")
    @ApiOperation(value = "编辑区域")
    public ApiResult<Void> editArea(@RequestBody Area area) {
        return areaService.editArea(area);
    }

    @DeleteMapping("/delById/{id}")
    @SysLog(desc = "删除区域")
    @ApiOperation(value = "删除区域")
    public ApiResult<Void> delById(@PathVariable Integer id) {
        return areaService.delById(id);
    }

    @GetMapping("/searchArea")
    @ApiOperation(value = "检索区域")
    public ApiResult<List<Area>> searchArea(@RequestParam String title) {
        return areaService.searchArea(title);
    }

    @GetMapping("/getAreaByParentId")
    @ApiOperation(value = "获取子节点")
    public ApiResult<List<Area>> getAreaByParentId(@RequestParam Integer parentId, @RequestParam Integer level) {
        return areaService.getAreaByParentId(parentId, level);
    }

    @GetMapping("/getArea4Search")
    @ApiOperation(value = "获取子节点")
    public ApiResult<List<Area4ChildVo>> getArea4Search(@RequestParam Integer parentId, @RequestParam Integer level) {
        return areaService.getArea4Search(parentId, level);
    }

    @GetMapping("/getAllArea")
    @ApiOperation(value = "区域树")
    public ApiResult<List<Area>> getAllArea() {
        return areaService.getAllArea();
    }

}